<template>
  <div class="search">
    <div class="container">
      <div class="corner">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>网站公告</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="tab">
        <ul class="tab-list">
          <li :class="{ pitch: active == 0 }" @click="active = 0">全部</li>
        </ul>
      </div>
      <div v-show="active == 0" class="list-box">
        <ul>
          <li v-for="item in listBulletinData" :key="item.id" class="detail-list" @click="GoDetail(item.id)">
            <div class="box">
              <div class="left">
                <img :src="item.coverImage" alt="">
              </div>
              <div class="right">
                <h5 class="title">
                  {{ item.bulletinTitle }}
                </h5>
                <div class="word-break text">
                  {{ item.bulletinIntroduct }}
                </div>
                <div class="time">{{ parseTime(item.createTime, "{y}-{m}-{d}") }}</div>
              </div>
            </div>
          </li>

        </ul>
        <div class="page">
          <!-- 分页 -->
          <el-pagination
            background
            layout="prev, pager, next"
            :page-sizes="[2, 5, 10, 20]"
            :page-size="pageSize"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { listBulletin } from '@/api/web-site-announcement'
export default {
  data() {
    return {
      active: 0,
      pageSize: 5,
      pageIndex: 1,
      total: 10,
      listBulletinData: []
    }
  },
  created() {
    this.listBulletin()
  },
  methods: {
    GoDetail(id) {
      this.$router.push({
        path: '/information-detail',
        query: {
          id,
          type: 0
        }
      })
    },
    listBulletin() {
      listBulletin(this.pageIndex, this.pageSize).then(res => {
        this.total = res.data.total
        this.listBulletinData = res.data.records
        const d = JSON.stringify(this.listBulletinData)
        localStorage.setItem('listBulletinData', d)
      })
    },
    // 页个数数改变的时候可获取当前显示个数
    handleSizeChange(size) {
      this.pageSize = size
    },
    // 页数改变的时候可获取当前显示当前页码数
    handleCurrentChange(currentPage) {
      console.log(currentPage)
      this.pageIndex = currentPage
      this.listBulletin()
    }
  }
}
</script>

<style lang="scss" scoped>
.search {
  background: #f5f5f5;
  .container {
    .corner {
      height: 30px;
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #707070;
      ::v-deep .el-breadcrumb__inner a,
      .el-breadcrumb__inner.is-link {
        color: #707070;
        font-weight: normal;
      }
      ::v-deep .el-breadcrumb__inner.is-link {
        color: #707070;
        font-weight: normal;
      }
    }
    .tab {
      background: #fafafa;
      .tab-list {
        display: flex;
        justify-content: space-between;
        height: 45px;
        line-height: 45px;
        width: 306px;
        padding-left: 40px;
        li {
          cursor: pointer;
        }
        .pitch {
          border-bottom: 2px solid #ff3b30;
          color: #ff3b30;
        }
        .unchecked {
          border-bottom: none;
        }
      }
    }
    .list-box {
      background: #ffffff;
      margin-bottom: 60px;
      cursor: pointer;
      .detail-list {
        padding: 0px 50px;

        .box {
          display: flex;
          border-bottom: 1px solid #e5e5e5;
          padding: 30px 0;
          .left {
            width: 228px;
            height: 132px;
            background: orchid;
            margin-right: 38px;
            img{
               width: 228px;
            height: 132px;
              object-fit: cover;
            }
          }
          .right {
            position: relative;
            .title {
              color: #333333;
              font-size: 16px;
              font-weight: bold;
              margin-bottom: 20px;
            }
            .text {
              width: 830px;
            }
            .time {
              position: absolute;
              bottom: 0;
              color: #c7c7cc;
            }
          }
        }
      }
      .page {
        margin-top: 40px;
        padding-bottom: 20px;
        display: flex;
        justify-content: center;
      }
    }
  }
  .el-pagination {
    height: 130px;
    display: flex;
    justify-content: center;
    align-items: center;
    // margin-top: 20px;
    background-color: #fff;
  }
  ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #fff;
    color: #ff3b30ff;
    border: 1px solid #ff3b30ff;
  }

  ::v-deep .el-pagination.is-background .el-pager li:not(.disabled) {
    // background-color: #fff;
    border: 1px solid #ddddddff;
  }
  ::v-deep .el-pagination.is-background .btn-prev {
    border: 1px solid #ddddddff;
    padding: 0 15px;
  }
  ::v-deep .el-icon-arrow-left:before {
    content: "上一页";
  }
  ::v-deep .el-pagination.is-background .btn-next {
    border: 1px solid #ddddddff;
    padding: 0 15px;
  }
  ::v-deep .el-icon-arrow-right:before {
    content: "下一页";
  }
}
</style>
